package main

import (
	"flag"
	"fmt"
)

/*相当于设置的默认值*/
var Input_Name = flag.String("name", "dabaojian", "input your name")
var Input_Age = flag.Int("age", 20, "input your age")
var Input_Gender = flag.String("gender", "male", "input your age")
var Input_flagvar int

func Init2() {
	flag.IntVar(&Input_flagvar, "flagname", 1234, "help message for flagname")
}

/**
go build flag.go 编译：
./flag -name=world 运行：
下面就能获取到运行时设置的参数，如果没设置，就是用默认值
 */
func main() {
	Init2()
	flag.Parse() //通过启动参数 获取flag的值


	//
	//fmt.Printf("args=%s, num=%d\n", flag.Args(), flag.NArg())
	//fmt.Printf("flag num=%d\n", flag.NFlag())
	//
	//for i := 0; i != flag.NArg(); i++ {
	//	fmt.Printf("arg[%d]=%s\n", i, flag.Arg(i))
	//}


	fmt.Println("name=", *Input_Name)
	fmt.Println("age=", *Input_Age)
	fmt.Println("gender=", *Input_Gender)
	fmt.Println("flagname=", Input_flagvar)
}